/**
 * UnitTest responsible for testing the Help.assertInterface method
 * 
 * @see Help
 */
new function ()
{
    /**
     * @interface
     * @private
     */
    function AnInterface () {};
    AnInterface.prototype=
    {
        niladicMethod: function () {}
    ,   dyadicMethod: function (a, b) {}
    };
    
    /////////////////////////////////////

    /**
     * @constructor
     * @private
     * @implements {Inteface}
     */
    function Implementor () {};
    Implementor.prototype=
    {
        niladicMethod: function () {}
    ,   dyadicMethod: function (x, y) {}
    };

    /////////////////////////////////////
    
    /**
     * A partially implementing class. This
     * should fail interface assertion. It does
     * not implement the 'dyadicMethod' method.
     * 
     * @constructor
     * @private
     */
    function MissingMethodImplementor () {};
    MissingMethodImplementor.prototype=
    {
        niladicMethod: function () {}
    };
    
    /////////////////////////////////////
    
    /**
     * A partially implementing class. This should
     * fail the interface assertion.
     * 
     * Even though the class implements the 'dyadicMethod'
     * it defined three parameters rather than two.
     * 
     * @constructor
     * @private
     */
    function BadArityImplementor () {};
    BadArityImplementor.prototype=
    {
        niladicMethod: function () {}
    ,   dyadicMethod: function (a, b, c) {}
    };
    
    /////////////////////////////////////
    
        
    TestCase
    (
        'HelpTest'
        
    ,   {
            /**
             * Log a message to the console if supported.
             *
             * @param {String} message
             *  The message to log
             * @return {void}
             * @private
             */
            log: function (message)
            {
                if (window.console && console.log)
                    console.log(message);
            }
            
            /**
             * Tests that Help.assertInterface works correctly. This help
             * method is used to ensure that classes used in the PureMvc
             * implementation adhere to their interfaces correctly.
             * 
             * @return {void}
             */
        ,   testAssertInterface: function ()
            {
                var assertionError= null
                ,   errorType= null
                
                try
                {
                    Help.assertInterface(AnInterface, Implementor);
                }
                catch (thrown)
                {
                    assertionError= thrown;    
                }
                
                
                assertNull("Interface should have been implemented, but an error was thrown", assertionError);
                
                assertionError= null;
                    
                try
                {
                    Help.assertInterface(AnInterface, MissingMethodImplementor)
                }
                catch (thrown)
                {
                    assertionError= thrown;
                }
                
                assertNotNull("An interface assertion error should have been thrown for missing methods"
                        , assertionError);
                
                assertSame("An " + Help.INTERFACE_METHOD_NOT_IMPLEMENTED 
                        + " error type should have been thrown"
                        , Help.INTERFACE_METHOD_NOT_IMPLEMENTED
                        , assertionError.type)
                        
                assertionError= null;
                
                try
                {
                    Help.assertInterface(AnInterface, BadArityImplementor);
                }
                catch (thrown)
                {
                    console.error(thrown.stack || thrown)
                    assertionError= thrown;
                }
                
                assertNotNull("Expected the BadArityImplementor to cause an error with type " + Help.INTERFACE_BAD_METHOD_SIGNATURE, assertionError);
                
                assertSame("The error thrown should have a type property of " + Help.INTERFACE_BAD_METHOD_SIGNATURE, 
                       Help.INTERFACE_BAD_METHOD_SIGNATURE, assertionError.type);
            }
        }
    );     
};
